
<template>
<div>
  <el-table :data="pageInfo" style="width: 100%">
    <el-table-column prop="id" label="流程定义id"/>
    <el-table-column prop="deploymentId" label="流程部署id"/>
    <el-table-column prop="key" label="流程定义key"/>
    <el-table-column prop="name" label="流程名称"/>
    <el-table-column prop="resourceName" label="流程资源"/>
    <el-table-column prop="version" label="版本"/>
    <el-table-column label="操作" width="300">
      <template #default="scope" >
        <el-button size="small" type="success" @click="lookmange(scope.row)">查看</el-button>
<!--        <el-button size="small" type="primary" @click="pending(scope.row)">挂起</el-button>-->
        <el-button size="small" type="danger"  @click="deleteMange(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div style="float: right;padding-top: 1%">
    <el-pagination
        v-model:current-page="pageNum"
        v-model:page-size="pageSize"
        background layout="prev, pager, next"
        :total="total"
        @current-change="handleCurrentChange"/>
  </div>
</div>

</template>

<style scoped>

</style>
<script setup lang="ts">

import {onMounted, ref} from "vue";
import {deleteMangeById, getprocesslists, suspendProcessDefinitionvue} from "../../api/flow";
import {ElMessage} from "element-plus";

let pageSize =ref(10)
let pageNum =ref(1)
let pageInfo = ref([])
let total  =ref(0)
let lookflag = ref(false)
let imglink = ref('')
onMounted(async () => {
  await query();
})
const query = async () => {
  let res = await getprocesslists({pageSize: pageSize.value, pageNum: pageNum.value});
  pageInfo.value = res.data.rows;
  total.value = res.data.total;
  console.log(res.data.rows)
}
const handleCurrentChange = async (val: number) => {
  pageNum.value = val;
  await query()
}
const lookmange =  (row) => {
  imglink.value = row.id;
  const downloadUrl = `${import.meta.env.VITE_HTTP}/flow/manage/showresource?pdid=${imglink.value}`;
  const newWindow = window.open(downloadUrl);
  if (newWindow) {
    // 新窗口已成功打开
  } else {
    ElMessage.error("加载失败")
  }
}
const pending = async (row) => {
  let res = await suspendProcessDefinitionvue({pdid:row.id,date:new Date()});
  if (res.code == 200) {
    ElMessage.success(res.data)
  }else{
    ElMessage.error(res.msg);
  }
}
const deleteMange = async (row) => {
  let res = await deleteMangeById({pdid:row.deploymentId});
  if (res.code == 200) {
    ElMessage.success(res.data)
    await query()
  }else{
    ElMessage.error(res.data);
  }
}
</script>
